//
//  JKRHomeViewController.m
//  YYKitTest
//
//  Created by tronsis_ios on 16/7/13.
//  Copyright © 2016年 tronsis_ios. All rights reserved.
//

#import "JKRHomeViewController.h"
#import "JKRTableView.h"
#import "WBStatusLayout.h"

@interface JKRHomeViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *layouts;
@end

@implementation JKRHomeViewController

static NSString *const identifier = @"HOMECELL";

- (instancetype)init {
    self = [super init];
    _tableView = [JKRTableView new];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _layouts = [NSMutableArray new];
    [self setNavBar];
    return self;
}

- (void)setNavBar {
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationbar_pop"] style:UIBarButtonItemStylePlain target:self action:@selector(qrCodeScanButtonClick:)];
    self.navigationItem.rightBarButtonItem = rightItem;
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationbar_friendattention_highlighted"] style:UIBarButtonItemStylePlain target:self action:@selector(friendAttentionButtonClick:)];
    self.navigationItem.leftBarButtonItem = leftItem;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _initView];
    [self loadData];
}

- (void)loadData {
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        for (int i = 0; i <= 7; i++) {
            NSData *data = [NSData dataNamed:[NSString stringWithFormat:@"weibo_%d.json", i]];
            WBTimelineItem *item = [WBTimelineItem modelWithJSON:data];
            for (WBStatus *status in item.statuses) {
                WBStatusLayout *layout = [[WBStatusLayout alloc] initWithStatus:status style:WBLayoutStyleTimeline];
            }
        }
    });
}

- (void)_initView {
    if ([self respondsToSelector:@selector( setAutomaticallyAdjustsScrollViewInsets:)]) {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    self.view.backgroundColor = kWBCellBackgroundColor;
    
    _tableView.frame = self.view.bounds;
    _tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
    _tableView.scrollIndicatorInsets = _tableView.contentInset;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.backgroundView.backgroundColor = [UIColor clearColor];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:identifier];
    [self.view addSubview:_tableView];
}

- (void)qrCodeScanButtonClick:(UIBarButtonItem *)sender {
    
}

- (void)friendAttentionButtonClick:(UIBarButtonItem *)sender {
    
}

#pragma mark - tableView数据量
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 12;
}
#pragma mark - tableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    cell.textLabel.text = [NSString stringWithFormat:@"%zd", indexPath.row];
    return cell;
}

@end
